package user.zc.excel.data.wrap;


import user.zc.excel.WriteDTO;
import user.zc.excel.data.builder.ColumnBuilder;
import user.zc.excel.data.builder.DataBuilder;
import user.zc.excel.data.builder.DataStyleBuilder;
import user.zc.excel.data.builder.TitleBuilder;
import user.zc.exception.ExcelExceptionEnum;

import java.util.List;

public class ExcelDataWrapper<T> extends AWrapper {

    private List<T> list;
    public ExcelDataWrapper(List<T> list,AWrapper next){
        super(next);
        this.list = list;
    }

    @Override
    public WriteDTO merge(WriteDTO writeDTO) {
        ExcelExceptionEnum.LIST_IS_EMPTY.assertNotEmpty(list);
        Class<T> clazz =  (Class<T>)list.get(0).getClass();
        writeDTO.setClazz(clazz);
        writeDTO.setDatas(list);
        writeDTO.setTitles(new TitleBuilder().collect(clazz));
        writeDTO.setColumns(new ColumnBuilder().collect(clazz));
        writeDTO.setStyles(new DataStyleBuilder().collect(clazz));
        writeDTO.setCells(new DataBuilder(writeDTO).collect(clazz));
        return writeDTO;
    }
}
